using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInputHandler : MonoBehaviour
{
    public void OnApplicationFocus(bool focus)
    {
        Cursor.lockState = focus ? CursorLockMode.Locked : CursorLockMode.None;
        Cursor.visible = !focus;
    }

    public bool CanProcessInput()
    {
        return Cursor.lockState == CursorLockMode.Locked;
    }

    public Vector3 GetMoveInput()
    {
        if (CanProcessInput() == false)
        {
            return Vector3.zero;
        }

        Vector3 move = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
        move = Vector3.ClampMagnitude(move, 1);

        return move;
    }

    public float GetLookInputsVertical()
    {
        return GetMouseOrStickLookAxis("Mouse Y");
    }

    public float GetLookInputsHorizontal()
    {
        return GetMouseOrStickLookAxis("Mouse X");
    }

    public float GetMouseOrStickLookAxis(string mouseInputName)
    {
        if (CanProcessInput() == false)
        {
            return 0f;
        }
        return Input.GetAxisRaw(mouseInputName);
    }

    public bool GetJump()
    {
        if (CanProcessInput() == false)
            return false;
        return Input.GetKeyDown(KeyCode.Space);
    }

    public int GetAttackId()
    {
        if(CanProcessInput() == false)
            return 0;   

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            return 1;
        }
        else if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            return 2;
        }
        return 0;
    }

    public bool GetWeapon()
    {
        return Input.GetKeyDown(KeyCode.Mouse1); 
    }

    public bool GetMission()
    {
        return Input.GetKeyDown(KeyCode.R);
    }
}
